﻿
using Microsoft.AspNetCore.Components;

namespace Bootstrap5.Abstractions;

public abstract class BootstrapChildContentWithChildCascadingComponentBase<TChildComponent,TParentComponent>:BootstrapChildContentComponentBase
     where TChildComponent :BootstrapComponentBase
    where TParentComponent : BootstrapComponentBase
{
    protected BootstrapChildContentWithChildCascadingComponentBase()
    {

    }
    [CascadingParameter]protected TParentComponent Parent { get; set; }

    protected override void OnInitialized()
    {
        ThrowIfParentNull();
    }

    protected virtual void ThrowIfParentNull()
    {
        if (Parent is null)
        {
            throw new CascadingValueNullException(typeof(TChildComponent).Name, typeof(TParentComponent).Name);
        }
    }
}


public abstract class BootstrapChildCascadingComponentBase<TChildComponent, TParentComponent> : BootstrapComponentBase
     where TChildComponent : BootstrapComponentBase
    where TParentComponent : BootstrapComponentBase
{
    protected BootstrapChildCascadingComponentBase()
    {

    }
    [CascadingParameter] protected TParentComponent Parent { get; set; }

    protected override void OnInitialized()
    {
        ThrowIfParentNull();
    }

    protected virtual void ThrowIfParentNull()
    {
        if (Parent is null)
        {
            throw new CascadingValueNullException(typeof(TChildComponent).Name, typeof(TParentComponent).Name);
        }
    }
}
